package com.qfedu.controller;

import com.qfedu.fmmall.entity.ShoppingCart;
import com.qfedu.fmmall.service.ShoppingCartService;
import com.qfedu.fmmall.utils.Base64Utils;
import com.qfedu.fmmall.vo.ResultStatus;
import com.qfedu.fmmall.vo.ResultVo;
import io.jsonwebtoken.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("shopcart")
@Api(tags = "购物车管理",value = "购物车增删改查")
public class ShopcartController {


    @Autowired
    private ShoppingCartService shoppingCartService;


    /**
     * 购物车接口
     * @Author Liux8
     * */

    @GetMapping("/list")
    public ResultVo listCarts(){
        //1.获取token
        //2.校验token
        return new ResultVo(ResultStatus.NO,"获取成功",null);
    }

    @PostMapping("/add")
    @ApiOperation("新增购物车")
    public ResultVo addCart(@RequestBody ShoppingCart cart,@RequestHeader("token")String token){
        ResultVo resultVo = shoppingCartService.addShoppingCart(cart);
        return resultVo;
    }

    @GetMapping("/list/{userId}")
    @ApiOperation("获取购物车列表")
    @ApiImplicitParam(dataType = "int",name="userId",required = true)
    public ResultVo listCart(@PathVariable Integer userId,@RequestHeader("token")String token){
        return shoppingCartService.listShoppingCartByUserId(userId);
    }

    @PostMapping("/update/{cid}/{cnum}")
    @ApiOperation("修改购物车数量")

    public ResultVo updateCartNum(@PathVariable("cid")Integer cartId,
                                  @PathVariable("cnum")Integer cartNum,
                                  @RequestHeader("token")String token){
        return shoppingCartService.updateCartNum(cartId,cartNum);
    }

    @GetMapping("/listByCIds/{CIds}")
    @ApiOperation("获取选中的购物车数据")
    public ResultVo listByCIds(@PathVariable("CIds") String CIds,
                               @RequestHeader("token")String token){
        return  shoppingCartService.listShopCartByCIds(CIds);
    }
}
